﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class DSTEXWBD14Data : BaseFunction
    {
        string WBBNEUBEN = "";
        byte[] b;
        string value;
        public DSTEXWBD14Data()
            : base()
        {

        }
        public DSTEXWBD14Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }        
        public DataSet GetWBBST(string intexidcard)
        {
            string TableName = "WBBST";
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal = null;
            try
            {
                 
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT WBBRWLFD	,WBBPOS,WBBART,	WBBFARBE,WBBBESCHICH,WBBVAR,WBBTAX"
                + ",WBBAUFKRS,WBBAUFLFD,WBBAUFPOS,WBBURLIEFSCH,WBBBEM,WBBNEUBEN,WBBNEUDAT"
                +" ,substr('000000000000'||Trim(WBBSTKNR),-12) as WBBSTKNR,WBBPACKNR,WBBAUFMSL,WBBPACKTYP,WBBLO,WBBLB,WBBLP,WBBISTKLG,WBBIGEW "
                +" FROM WBBST W WHERE   WBBMANDANT = '00' "
                + " AND WBBRWLFD=:WBBRWLFD";
                orlReadCommand.Parameters.Add("WBBRWLFD", OracleType.NVarChar).Value = intexidcard;
                //WBBBESCHICH
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = TableName;
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = TableName;
                    
                }
                if (tableLocal.Rows.Count > 0)
                {
                    WBBNEUBEN = tableLocal.Rows[0]["WBBNEUBEN"].ToString();
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public DataSet GetHRSTAMM(string NEUBEN)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            string TableName = "HRSTAMM";
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM HRSTAMM   WHERE "
                                                + " HRBENID = :HRBENID ";
                or1.Parameters.Add("HRBENID", OracleType.NVarChar).Value = NEUBEN;                
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = TableName;
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet BuildData(string intexidcard )
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            try
            {
                setResult = GetWBBST(intexidcard);
                setReturn.Merge(setResult);
                setResult = GetHRSTAMM(WBBNEUBEN);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}